package com.gopay.common.cps.dao.cbrmb.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cipher.utils.LoggerMaskUtils;
import com.gopay.common.cipher.utils.SensitiveInfoUtils;
import com.gopay.common.cps.dao.cbrmb.CbRmbBlackListDAO;
import com.gopay.common.domain.cbrmb.CbRmbBlacklist;
import com.gopay.common.exception.GopayException;

@Repository("cbRmbBlackListDao")
public class CbRmbBlackListDAOImpl extends BaseDAOImpl<CbRmbBlacklist, Long> implements CbRmbBlackListDAO {
    private static final Logger LOG = LoggerFactory.getLogger(CbRmbBlackListDAOImpl.class);
    @Override
    public CbRmbBlacklist getByNameAndIdCard(String personalName, String idCardNo) throws GopayException {
        LOG.info("\n\n>>>>> 查询姓名身份证黑名单信息，姓名：{}，身份证号：{} <<<<<\n\n", personalName,LoggerMaskUtils.maskString(idCardNo));
        String hql = "from CbRmbBlacklist c where c.deleteStatus='0' and c.personalName in (:personalName) and c.idCardNo in (:idCardNo)";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("personalName", SensitiveInfoUtils.getAllHisCipherText(personalName));
        param.put("idCardNo", SensitiveInfoUtils.getAllHisCipherText(idCardNo));
        List<CbRmbBlacklist> list = findByHql(hql, param);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public CbRmbBlacklist getByCorpName(String corpName) throws GopayException {
        LOG.info("\n\n>>>>> 查询企业黑名单信息，企业名称：{} <<<<<\n\n", corpName);
        String hql = "from CbRmbBlacklist c where c.deleteStatus='0' and c.corporationName in (:corpName)";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("corpName", corpName);
        List<CbRmbBlacklist> list = findByHql(hql, param);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public CbRmbBlacklist getByBankCard(String bankCardNo) throws GopayException {
        LOG.info("\n\n>>>>> 查询银行卡黑名单信息，卡号：{} <<<<<\n\n", LoggerMaskUtils.maskString(bankCardNo));
        String hql = "from CbRmbBlacklist c where c.deleteStatus='0' and c.bankCardNo in (:bankCardNo)";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("bankCardNo", SensitiveInfoUtils.getAllHisCipherText(bankCardNo));
        List<CbRmbBlacklist> list = findByHql(hql, param);
        if (list != null && list.size() > 0) {
            LOG.info("##### 该银行卡在黑名单中！ #####");
            return list.get(0);
        }
        return null;
    }

}
